import time

from appium import webdriver
from appium.options.android import UiAutomator2Options

from config import app_path, package_name, des_caps


def app_driver():
    # 初始化设备配置信息
    option = UiAutomator2Options().load_capabilities(des_caps)
    # 创建驱动对象
    driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=option)
    return driver


def driver_quit(driver):
    time.sleep(3)
    driver.quit()

def app_install(driver, pck_name=package_name,path=app_path):

    #判断App是否存在
    if driver.is_app_installed(pck_name):
       driver.remove_app(pck_name)
    else:
        driver.install_app(path)
#value="//class的值[@属性名='属性值']"
if __name__ == '__main__':
    driver = app_driver()
    app_install(driver)